--[[
	提交上行短信后返回响应消息
--]]

function string.split(str, delimiter)
        if str==nil or str=='' or delimiter==nil then
                return nil
        end

    local result = {}
    for match in (str..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match)
    end
    return result
end

local count = 0

for i,v in ipairs(ARGV) do

    local args = string.split(v, ":")
    
    local result = redis.call("zrem", KEYS[2], args[1])
    
    if (result == 1) then
    
        local ntfhvalue = redis.call("hmget", "SMMoDealHash:"..args[1], "ISMCacheKey", "IRptSnPart1", "IRptSnPart2", "IRptSnPart3", "ISendTimes", "ILastSendTime")
    
        local cacheKey = ntfhvalue[1]
        
        if (cacheKey ~= nil and cacheKey ~= false) then
        
            redis.call("del", "SMMoDealHash:"..args[1])
            redis.call("lpush", KEYS[3], cacheKey)
            redis.call("hmset", "SMInfo:"..cacheKey, "MoResult", "0",  "MoResultDesc", "sucess")
        end
    else
        redis.call("zadd", KEYS[1], args[2], args[1])
    end

end

return count